home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / files.swg / 0100_Convert a COM file to an INLINE.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-11-29  |  8.5 KB  |  297 lines

  1. {
  2.                   =======================================
  3.  
  4.                          INLINE (c) AVC Software
  5.                                Cardware
  6.  
  7.                    Convert  a  COM file  into  an INLINE
  8.                    instruction -or into a  binary array-
  9.  
  10.                   =======================================
  11.  
  12.    Convert a COM file into a Pascal Inline() Instruction.
  13.  
  14.    Be  carefull, the  COM  file must  don't  have the  end of  program code
  15.    (Mov Ax, 4C00h  followed by Int 21h)
  16.  
  17.  
  18.  
  19.                ╔════════════════════════════════════════╗
  20.                ║                                        ║░
  21.                ║          AVONTURE CHRISTOPHE           ║░
  22.                ║              AVC SOFTWARE              ║░
  23.                ║     BOULEVARD EDMOND MACHTENS 157/53   ║░
  24.                ║           B-1080 BRUXELLES             ║░
  25.                ║              BELGIQUE                  ║░
  26.                ║                                        ║░
  27.                ╚════════════════════════════════════════╝░
  28.                ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  29.  
  30. }
  31.  
  32. Program Com2Inline;
  33.  
  34. Uses Crt;
  35.  
  36. Const
  37.    Hexa : Array [0..15] of Char =
  38.        ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  39.  
  40. Var
  41.    Ch1 , Ch2 : Byte;
  42.    Ch3 , Ch4 : Byte;
  43.    Ch        : Char;
  44.  
  45. Function Word2Hex(Number: Word) : String;
  46. Begin
  47.  
  48.   Ch1 := (Number SHR 8) SHR 4;
  49.   Ch2 := (Number SHR 8) - (Ch1 SHL 4);
  50.   Ch3 := (Number AND $FF) SHR 4;
  51.   Ch4 := (Number AND $FF) - (Ch3 SHL 4);
  52.  
  53.   Word2Hex := Hexa[Ch1]+Hexa[Ch2]+Hexa[Ch3]+Hexa[Ch4];
  54.  
  55. End;
  56.  
  57. Function Byte2Hex(Number: Byte) : String;
  58. Begin
  59.  
  60.     Ch1 := Number SHR 4;
  61.     Ch2 := Number - (Ch1 SHL 4);
  62.  
  63.     Byte2Hex := Hexa[Ch1]+Hexa[Ch2];
  64.  
  65. End;
  66. Procedure Traitement;
  67.  
  68. Type Buf   = Array[0..65534] of Byte;
  69.  
  70.  
  71. Var InFile        : File;
  72.     OutFile       : Text;
  73.     Buffer        : ^Buf;
  74.     Param1, NomF  : String;
  75.     I, J          : Word;
  76.     Extension     : Boolean;
  77.     NLus          : Integer;
  78.  
  79. Begin
  80.  
  81.    I := 0; J := 0; Extension := False;
  82.    For i := 1 to Length (Param1) do
  83.        If (Param1[i] = '.') then Begin
  84.            Extension := True;
  85.            J := I;
  86.        End;
  87.    If Not Extension then Param1 := Param1+'.COM'
  88.    Else J := Length(Param1)+1;
  89.    NomF   := Copy (Param1,1,Length(Param1)-3)+'INL';
  90.  
  91.    Assign  (InFile,Param1);
  92.    Assign  (OutFile,NomF);
  93.    Reset   (InFile,1);
  94.    Rewrite (OutFile);
  95.  
  96.    New (Buffer);
  97.  
  98.    BlockRead (InFile, Buffer^, 65535, NLus);
  99.    Close (InFile);
  100.  
  101.    Writeln (OutFile,'{Inline source for ',Param1,' created by AVONTURE Christophe }');
  102.    Writeln (OutFile,'');
  103.  
  104.    If ParamCount = 1 then Write (OutFile,'Inline(')
  105.    Else Begin
  106.        Writeln (OutFile, 'const ',Copy (NomF, 1, Length(NomF)-4),
  107.                 ' : Array [1..',NLus,'] of byte = (');
  108.        Write (OutFile,'       ');
  109.    End;
  110.  
  111.    For I := 0 to NLus-1 do Begin
  112.        If (I mod 17 = 16) then Begin
  113.            Writeln (OutFile,'');
  114.            Write (OutFile,'       ');
  115.        End;
  116.        If ParamCount = 1 then
  117.           If Not (I = NLus-1) then Write (OutFile, '$',Byte2Hex(Buffer^[i]),'/')
  118.           Else Write (OutFile, '$',Byte2Hex(Buffer^[i]))
  119.        Else If Not (I = NLus-1) then Write (OutFile, '$',Byte2Hex(Buffer^[i]),',')
  120.           Else Write (OutFile, '$',Byte2Hex(Buffer^[i]));
  121.    End;
  122.  
  123.    Write (OutFile,');');
  124.    Close (OutFile);
  125.  
  126. End;
  127.  
  128. Begin
  129.  
  130.    If ((ParamCount = 1) or (ParamCount = 2)) then Traitement
  131.    Else Begin
  132.        ClrScr;
  133.        GotoXy (0, 2);
  134.        Writeln ('');
  135.        Writeln ('Inline by AVONTURE Christophe');
  136.        Writeln ('-----------------------------');
  137.        Writeln ('');
  138.        Writeln ('You must specify the name of the COM file as parameter.');
  139.        Writeln ('');
  140.        Writeln ('    Inline Scancode.com or Inline Scancode');
  141.        Writeln ('');
  142.        Writeln ('A .INL file will be created.');
  143.        Writeln ('');
  144.        Writeln ('If you type only one parameter, then the result will be like');
  145.        Writeln ('');
  146.        Writeln ('    Inline ($E9/$F2/$00/$20/$20/ ..... ');
  147.        Writeln ('');
  148.        Writeln ('If you type a second parameter (anything), then the result will be like');
  149.        Writeln ('');
  150.        Writeln ('    Const SCANCODE : Array [1..364] of byte =  ');
  151.        Writeln ('                     ($E9,$F2,$00,$20, ..... );');
  152.        Writeln ('');
  153.        Writeln ('');
  154.        TextAttr := 15;
  155.        Ch := ReadKey; If Ch = #0 then Ch := ReadKey;
  156.    End;
  157.  
  158. End.
  159.  
  160. { -------------------------------- cut here ------------------------------- }
  161.  
  162. { Example program }
  163.  
  164. Uses Crt;
  165.  
  166. Begin
  167.  
  168.    Inline($EB/$01/$90/$B4/$01/$B5/$20/$CD/$10);           {Hide the cursor}
  169.  
  170.    Inline($B8/$03/$00/$CD/$10);                              {Clear screen}
  171.  
  172.    Writeln ('Demo of Inline code into a Pascal program :'#10#13#10#13);
  173.  
  174.    Writeln ('Press a key, the screen will be erased.');
  175.  
  176.    Inline($EB/$01/$90/$B4/$07/$CD/$21);                      {ReadKey code}
  177.  
  178.    Inline($EB/$01/$90/$B4/$00/$B0/$03/$CD/$10);              {Clear screen}
  179.  
  180.    TextAttr := 158;
  181.  
  182.    Writeln ('These two function - ReadKey & ClrScr - has been coded Inline.'
  183.       #10#13#10#13);
  184.  
  185.    Inline($EB/$01/$90/$B4/$07/$CD/$21);                    {Wait for a key}
  186.  
  187.    Writeln ('This line is blinking.  You don't like that.  OK!'#10#13#10#13);
  188.  
  189.    Inline($EB/$01/$90/$B4/$07/$CD/$21);                    {Wait for a key}
  190.  
  191.  
  192.                        {Disable the text blinking; color attribut after 128}
  193.    Inline($EB/$01/$90/$B4/$10/$B0/$03/$B3/$00/$CD/$10);
  194.  
  195.    Inline($EB/$01/$90/$B4/$07/$CD/$21);                    {Wait for a key}
  196.  
  197.    Writeln ('Wow.  What a cool effect!  Isn''t it!'#10#13#10#13);
  198.  
  199.    Inline($EB/$01/$90/$B4/$07/$CD/$21);                    {Wait for a key}
  200.  
  201.                                               {Restore the normal attribut}
  202.    Inline($EB/$01/$90/$B4/$10/$B0/$03/$B3/$01/$CD/$10);
  203.  
  204.    Writeln ('Restore the normal attribut.'#10#13#10#13);
  205.  
  206.    Inline($EB/$01/$90/$B4/$07/$CD/$21);                    {Wait for a key}
  207.  
  208. End.
  209.  
  210. { Severall Inline instruction based on some assembler program I have wrotte.
  211.  
  212.   When you want writte an assembler program for convert it into inline
  213.   command, take the following model:
  214.  
  215. CSEG        Segment public
  216.         Org    0100h
  217.  
  218.         Assume    CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
  219.  
  220. Entry:        Jmp    Begin        ; Entry Point
  221.  
  222. Begin:
  223.                 ; CODE HERE YOUR ASSEMBLER INSTRUCTION
  224.  
  225.  
  226. ; PLEASE READ: NEVER CODE A RET OR IRET INSTRUCTION!!!!!!
  227.  
  228.                 Ret   <===  NO!!!!
  229.  
  230. CSeg            Ends
  231.             End     Entry
  232.  
  233.  
  234. For example, the code for initialize the 80*25 video mode will be the
  235. following:
  236.  
  237. CSEG        Segment public
  238.         Org    0100h
  239.  
  240.         Assume    CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
  241.  
  242. Entry:        Jmp    Begin        ; Entry Point
  243.  
  244. Begin:          Mov  Ax, 0003h
  245.                 Int  10h
  246.  
  247. CSeg            Ends
  248.             End     Entry
  249.  
  250. You can compile this code into a COM file and then, launch the Inline program
  251. for convert it into an Inline instruction. }
  252.  
  253. {Inline source for CEPARTI.COM created at 18:0:6 by AVC Software, Inc.}
  254. {Make a sound with the speaker}
  255.  
  256. Inline($EB/$01/$90/$BA/$88/$13/$BB/$64/$00/$B0/$B6/$E6/$43/$8B/$C3/$E6/
  257.        $42/$8A/$C4/$E6/$42/$E4/$61/$0C/$03/$E6/$61/$43/$B9/$90/$01/$E2/$FE/
  258.        $4A/$75/$E9/$E4/$61/$24/$FC/$E6/$61/$BA/$88/$13/$BB/$EC/$13/$B0/$B6/
  259.        $E6/$43/$8B/$C3/$E6/$42/$8A/$C4/$E6/$42/$E4/$61/$0C/$03/$E6/$61/$4B/
  260.        $B9/$90/$01/$E2/$FE/$4A/$75/$E9/$E4/$61/$24/$FC/$E6/$61/$B8/$00/$4C/
  261.        $CD/$21/$4D/$73/$44/$6F/$73);
  262.  
  263. {Inline source for CURSOFF.COM created at 14:34:48 by AVC Software, Inc.}
  264. {Hide the cursor}
  265.  
  266. Inline($EB/$01/$90/$B4/$01/$B5/$20/$CD/$10);
  267.  
  268. {Inline source for CURSON.COM created at 14:34:54 by AVC Software, Inc.}
  269. {Show the cursor}
  270.  
  271. Inline($EB/$01/$90/$B4/$01/$B1/$07/$B5/$06/$CD/$10);
  272.  
  273. {Inline source for INITMODE.COM created at 14:35:15 by AVC Software, Inc.}
  274. {initialize a video mode}
  275.  
  276. Inline($B8/Mode/0/$CD/$10);
  277.  
  278. {Inline source for READKEY.COM created at 15:56:46 by AVC Software, Inc.}
  279. {ReadKey}
  280.  
  281. Inline($EB/$01/$90/$B4/$07/$CD/$21);
  282.  
  283. {Inline source for RESETFON.COM created at 13:2:22 by AVC Software, Inc.}
  284. {Restore the Ascii font}
  285.  
  286. Inline($EB/$01/$90/$B8/$04/$11/$B3/$00/$CD/$10/$B8/$04/$11/$B3/$01/$CD/
  287.        $10);
  288.  
  289. {Inline source for TXTCLIF.COM created at 15:36:36 by AVC Software, Inc.}
  290. {Disable the text blinking}
  291.  
  292. Inline($EB/$01/$90/$B4/$10/$B0/$03/$B3/$00/$CD/$10);
  293.  
  294. {Inline source for TXTCLIT.COM created at 15:36:44 by AVC Software, Inc.}
  295. {Enable the text blinking}
  296.  
  297. Inline($EB/$01/$90/$B4/$10/$B0/$03/$B3/$01/$CD/$10);